<?php
class Jingdian_model extends base_Model
{
    public function __construct()
    {
        $this->load->database();
    }


    public function getList($data = array())
    {

        if(!empty($data['city']))
        {
            $this->db->where('cityId', $data['city']);
        }


        if(!empty($data['type']))
        {
            $this->db->where('type', $data['type']);
        }else{
            $this->db->where('type !=', 2);
        }

        $this->db->where('status', 'VALID');

        if( !empty($data['limit']))
        {
            $offset = empty($data['offset'])?0:$data['offset'];
            $this->db->limit( $data['limit'],$offset);
        }

        $this->db->select('id, thumb, country, city, summary, name, subTitle');
        $this->db->from('mod_scenic_spot');
        $query = $this->db->get()->result_array();

        $items = array();
        if(!empty($query))
        {
            foreach($query as &$v)
            {
                $v['thumb'] = $this->img($v['thumb']);
                $items[] = $v;
            }

        }
        return $items;
    }

    function detail($id)
    {

        $this->db->select('id,thumb,name,subTitle,images,summary,address,lng,lat,website,descOpenTime,descTickets,zan');
        $this->db->where('id',$id);
        $this->db->from('mod_scenic_spot');
        $query = $this->db->get()->row_array();
        
        $query['thumb'] = $this->img($query['thumb']);
        
        if(!empty($query['images']))
        {
            $images = explode('|',$query['images']);
            foreach ($images as $img)
            {
                $query['imgs'][] = $this->img($img);
            }
        }
        unset($query['images']);
	
		if(empty($query['zan']))
		    $query['zan']='0';
		
		return $query;
    }




}
